const mongoose = require('mongoose')

const Schema = mongoose.Schema
const Types = Schema.Types

const Book = new Schema({
  id: Types.ObjectId,
  name: {
    type: Types.String,
    required: true,
    index: 1
  },
  author: {
    type: Types.String,
    index: 1
  },
  size: Types.Number,
  cover: Types.Buffer,
  uri: Types.String,
  thirdPartyUri: [{
    uriName: {
      type: Types.String,
      required: true
    },
    uri: {
      type: Types.String,
      required: true
    },
    provider: {
      type: Types.String,
      required: true
    },
    comment: Types.String
  }],
  createTime: {
    type: Types.Date,
    default: Date.now,
    index: 1
  },
  creator: {
    type: Types.String,
    required: true,
    index: 1
  }
})

module.exports = mongoose.model('Book', Book)
